<?php

declare(strict_types=1);

namespace App\Request\Web;

use Hyperf\Validation\Request\FormRequest;

class LoginRequest extends FormRequest
{

    public function authorize(): bool
    {
        return true;
    }

    public function rules(): array
    {
        return [
            'email' => [
                'required',
                'email:rfc,dns',
                'max:100'
            ],
            'password' => [
                'required',
                'string',
                'min:8',
                'regex:/^(?=.*[A-Za-z])(?=.*\d).+$/'
            ]
        ];
    }

    public function messages(): array
    {
        return [
            'email.required' => '邮箱不能为空',
            'email.email' => '邮箱格式不正确',
            'email.max' => '邮箱不能超过100个字符',

            'password.required' => '密码不能为空',
            'password.min' => '密码至少8个字符',
            'password.regex' => '密码必须包含字母和数字'
        ];
    }

    public function attributes(): array
    {
        return [
            'email' => '邮箱',
            'password' => '密码',
        ];
    }
}
